package com.summerbird.mallchat.common.chat.service.helper;

import cn.hutool.core.lang.Pair;
import com.summerbird.mallchat.common.user.domain.enums.ChatActiveStatusEnum;
import org.apache.commons.lang3.StringUtils;

/**
 * @description: 成员列表工具类
 * @author SummerBird
 * @date 2024/1/20 9:52
 * @version 1.0
 */
public class ChatMemberHelper {
    private static final String SEPARATOR = "_";

    public static Pair<ChatActiveStatusEnum, String> getCursorPair(String cursor){
        ChatActiveStatusEnum activeStatusEnum = ChatActiveStatusEnum.ONLINE;
        String timeCursor = null;
        if(StringUtils.isNotEmpty(cursor)){
            String activeStr = cursor.split(SEPARATOR)[0];
            String timeStr = cursor.split(SEPARATOR)[1];
            activeStatusEnum = ChatActiveStatusEnum.of(Integer.parseInt(activeStr));
            timeCursor = timeStr;
        }
        return Pair.of(activeStatusEnum, timeCursor);
    }

    public static String generateCursor(ChatActiveStatusEnum activeStatusEnum, String timeCursor) {
        return activeStatusEnum.getStatus() + SEPARATOR + timeCursor;
    }
}
